package com.tanhua.test;

import com.huanxin.HuanxinTemplate;
import com.tanhua.TanhuaAppServerApplication;
import com.tanhua.domain.User;
import com.tanhua.dubbo.UserAPI;
import com.tanhua.util.GenerateCode;
import org.apache.dubbo.config.annotation.DubboReference;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = TanhuaAppServerApplication.class)
public class HuanxinTemplateTest01 {

    @Autowired
    private HuanxinTemplate huanxinTemplate;

    @DubboReference
    private UserAPI userAPI;

    @Test
    public void test(){
        huanxinTemplate.createUser("user03","123456");
        System.out.println("ok");
    }

    @Test
    public void test01(){
        huanxinTemplate.sendMsg("hx1","{\"userId\":106,\"huanXinId\":\"hx106\",\"nickname\":\"黑马小妹\",\"strangerQuestion\":\"你喜欢去看蔚蓝的大海还是去爬巍峨的高山？\",\"reply\":\"我喜欢秋天的落叶，夏天的泉水，冬天的雪地，只要有你一切皆可~\"}");
    }

    @Test
    public void register(){
        for (int i=1;i<=106;i++){
            //从tb_user取出用户信息
            User user = userAPI.findById(i);
            //修改用户hxuser和hxpassword
            if(user!=null){
                user.setHxUser("hx"+user.getId());
                user.setHxPassword(GenerateCode.getCode());
                //提交环信
                huanxinTemplate.createUser(user.getHxUser(),user.getHxPassword());
                //提交tb_user
                userAPI.update(user);
            }



        }

    }


}
